package ar.edu.utn.frsf.proyectofinal.sistemadecontrolmodbus.presentation.controller.user.devicedata;

import java.util.ArrayList;
import java.util.List;

import ar.edu.utn.frsf.proyectofinal.sistemadecontrolmodbus.service.CompoundCommandService;
import ar.edu.utn.frsf.proyectofinal.sistemadecontrolmodbus.devicecontroller.command.Command;

/**
 * 
 * Este Bean es utilizado en las vistas
 * simpleuser/devicedata.xhtml
 */
public class CompoundCommandBean {
	
	private CompoundCommandService commandServ;
	private Integer value;
	
	public CompoundCommandBean(CompoundCommandService al) {
		commandServ = al;
	}
	public String getName(){
		return commandServ.getName();
		
	}
	
	public Integer getValue(){
		return value;
	}
	
	public void setValue(Integer integ){
		this.value = integ;
	}
	
	public void set(){
		commandServ.set(value);
	}
	
	public String getState(){
		int state = commandServ.getState();
		switch(state){
		    case Command.DONE: return "devicedata.command.state.done";
		    case Command.FAIL: return "devicedata.command.state.fail";
		    case Command.NOT_EXECUTING: return "devicedata.command.state.notexecuting";
		    case Command.PROCESSING: return "devicedata.command.state.processing";
		    case Command.WAITING: return "devicedata.command.state.waiting";
		}
		return null;
	}
	
	public boolean isDisabledbtn(){
		return commandServ.getState() == Command.WAITING || commandServ.getState() == Command.PROCESSING ;
	}
	public static List<CompoundCommandBean> wrap(
			List<CompoundCommandService> compoundCommandsService) {
		ArrayList<CompoundCommandBean> ret = new ArrayList<CompoundCommandBean>();
		for(CompoundCommandService al: compoundCommandsService){
			ret.add(new CompoundCommandBean(al));
		}
		return ret;
	}

}
